import request from '@/config/axios'

import { BaseModel } from '@/api/common/baseModel'

export interface Model extends BaseModel {
  handlerName: string
  handlerParam: string
  cronExpression: string
  retryCount: number
  retryInterval: number
  monitorTimeout: number
  createTime: Date
}

// 任务列表
export const getPage = (params: PageParam) => {
  return request.get({
    url: import.meta.env.VITE_BASE_ROLE + '/userCenter/job/job/page.json',
    params
  })
}

// 任务详情
export const getById = (id: string) => {
  return request.get({
    url: import.meta.env.VITE_BASE_ROLE + '/userCenter/job/job/getById.json?id=' + id
  })
}

// 修改定时任务调度
export const update = (data: Model) => {
  return request.put({
    url: import.meta.env.VITE_BASE_ROLE + '/userCenter/job/job/update.json',
    data
  })
}

// 删除定时任务调度
export const del = (id: string) => {
  return request.delete({
    url: import.meta.env.VITE_BASE_ROLE + '/userCenter/job/job/del.json?id=' + id
  })
}

// 定时任务立即执行一次
export const runJob = (id: string) => {
  return request.put({
    url: import.meta.env.VITE_BASE_ROLE + '/userCenter/job/job/trigger?id=' + id
  })
}

// 获得定时任务的下 n 次执行时间
export const getJobNextTimes = (id: string) => {
  return request.get({
    url: import.meta.env.VITE_BASE_ROLE + '/userCenter/job/job/get_next_times?id=' + id
  })
}
